/* Code based on the one available here: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet */

(function() {
  var el=window.document.createElement('div'),
   b=window.document.getElementsByTagName('body')[0];
   otherlib=false,
   msg='';
  el.style.position='fixed';
  el.style.height='32px';
  el.style.width='220px';
  el.style.marginLeft='-110px';
  el.style.top='0';
  el.style.left='50%';
  el.style.padding='5px 10px';
  el.style.zIndex = 1001;
  el.style.fontSize='12px';
  el.style.color='#222';
  el.style.backgroundColor='#f99';
  if(typeof jQuery!='undefined') {
 msg='This page already using jQuery v'+jQuery.fn.jquery;
 return showMsg();
  } else if (typeof $=='function') {
 otherlib=true;
  }
  // more or less stolen form jquery core and adapted by paul irish
  function getScript(url,success){
 var script=window.document.createElement('script');
 script.src=url;
 var head=window.document.getElementsByTagName('head')[0],
  done=false;
 // Attach handlers for all browsers
 script.onload=script.onreadystatechange = function(){
   if ( !done && (!this.readyState
     || this.readyState == 'loaded'
     || this.readyState == 'complete') ) {
  done=true;
  success();
  script.onload = script.onreadystatechange = null;
  head.removeChild(script);
   }
 };
 head.appendChild(script);
  }
  getScript('http://code.jquery.com/jquery-1.5.2.min.js',function() {
 if (typeof jQuery=='undefined') {
   msg='Sorry, but jQuery wasn\'t able to load';
 } else {
   msg='This page is now jQuerified with v' + jQuery.fn.jquery;
   if (otherlib) {msg+=' and noConflict(). Use $jq(), not $().';}
 }
 return showMsg();
  });
  function showMsg() {
 el.innerHTML=msg;
 b.appendChild(el);
 window.setTimeout(function() {
   if (typeof jQuery=='undefined') {
  b.removeChild(el);
   } else {
  jQuery(el).fadeOut('slow',function() {
    jQuery(this).remove();
  });
  if (otherlib) {
    $jq=jQuery.noConflict();
  }
   }
window.setTimeout(moover,500);
 } ,500);
  };
function moover(){
  var tryagain=true;
  if(jQuery){
    if(jQuery('#wikipreview').length>0 && jQuery('#wikipreviewtitle').length>0 && jQuery('form[name=wiki_edit]').length>0)
    {
      var wikipreview = jQuery('#wikipreview');
      var wikipreviewtitle = jQuery('#wikipreviewtitle');
      var formwiki_edit = jQuery('form[name=wiki_edit]');

      var wikieditor_tds = formwiki_edit.find('td.vt');

      //0 is the editor, 1 is the help bubble
      if(wikieditor_tds.length>1)
      {
        var helpBubble = jQuery(wikieditor_tds[1]);
        var mainTr = jQuery(helpBubble[0].parentNode);
        var table4Editor = jQuery(helpBubble[0].parentNode.parentNode);

        var newTd = jQuery('<td>').addClass('vt');
        mainTr.append(newTd);
        newTd.append(wikipreviewtitle,wikipreview);

        var newTr = jQuery('<tr>');
        table4Editor.append(newTr);
        newTr.append(helpBubble);

        tryagain=false;
      }
    }
  }
  if(tryagain) window.setTimeout(moover,500);
};

})();


